package com.ddzh.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ddzh.mapper.AuthMenuTreeVoMapper;
import com.ddzh.service.AuthMenuTreeVoService;
import com.ddzh.vo.AuthMenuTreeVo;
import org.apache.dubbo.config.annotation.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AuthMenuTreeVoServiceImpl extends ServiceImpl<AuthMenuTreeVoMapper,AuthMenuTreeVo> implements AuthMenuTreeVoService {

    @Override
    public AuthMenuTreeVo getAuthMenuByUsername(String username) {

        AuthMenuTreeVo authVo = new AuthMenuTreeVo();
        authVo.setUserName(username);
        String password = this.baseMapper.getPasswordByUsername(username);
        authVo.setPassword(password);
        //查询所有用户的角色名
        List<String> roleList = this.baseMapper.getRoleByUsername(username);
        authVo.setRoleNameList(roleList);
        return authVo;
    }

    @Override
    public List<AuthMenuTreeVo> getAuthMenuByUsername() {

        List<AuthMenuTreeVo> list = new ArrayList<>();
        //查询用户中所有用户名
        List<String> userNameList = this.baseMapper.findAllUsername();

        for (String username : userNameList) {
            AuthMenuTreeVo authVo = new AuthMenuTreeVo();
            String password = this.baseMapper.getPasswordByUsername(username);
            //查询所有用户的角色名
            List<String> roleList = this.baseMapper.getRoleByUsername(username);
            authVo.setRoleNameList(roleList);
            list.add(authVo);
        }
        return list;
    }
}
